﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WHW_NetUtility
{
    class Log4Helper
    {
        /*log4net使用方法：
         * 1.添加引用（log4net.dll可以放在bin/debug下）
         * 2.添加app.config(有时会自动生成，只需要在此配置文件中添加log4net的配置就可以了)
         * 3.在属性--> AssemblyInfo.cs中添加[assembly:log4net.Config.XmlConfigurator(Watch =true)]
         * 4.调用如下函数
         */
        private static  log4net.ILog Log;
        public static void init()
        {
            FileInfo fileInfo = new FileInfo(Environment.CurrentDirectory + "\\Config\\runLog.config");
            log4net.Config.XmlConfigurator.Configure(fileInfo);
            Log = log4net.LogManager.GetLogger("runLogger");
        }
        public static void init(string path)
        {
            FileInfo fileInfo = new FileInfo(path);
            log4net.Config.XmlConfigurator.Configure(fileInfo);
            Log = log4net.LogManager.GetLogger("runLogger");
        }
        public static void init(string path,string loggerName)
        {
            FileInfo fileInfo = new FileInfo(path);
            log4net.Config.XmlConfigurator.Configure(fileInfo);
            Log = log4net.LogManager.GetLogger(loggerName);
        }
        public static void WriteLog(Exception ex)
        {
            Log.Error(ex);
        }

        public static void WriteLog(string msg)
        {
            Log.Info(msg);
        }

        public static void WriteLog(string className, Exception ex)
        {
            Log?.Error(ex);
        }
        public static void WriteLogFatal(string className, string info)
        {
            Log.Fatal(info);
        }
        public static void WriteLog(string className, string msg)
        {
            Log?.Info(msg);
        }
        public static void WriteLogError(string msg)
        {
            Log?.Error(msg);
        }
    }
}
